//383.赎金信
//https://leetcode.cn/problems/ransom-note/?envType=daily-question&envId=2024-01-07
class Solution {
public:
    bool canConstruct(string ransomNote, string magazine) { //也可以使用hash
        sort(ransomNote.begin(),ransomNote.end()); //O(nlogn)
        sort(magazine.begin(),magazine.end());

        int n = ransomNote.size();
        int pos = 0;
        for(char c:magazine) //o(n)
        {
            if(pos == n) break;
            if(ransomNote[pos] == c) ++pos;
        }
        return pos == n;
    }
};
